package itheima.itheima_225;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/*p225
            1.定义学生类
            2.创建Collection对象
            3.创建学生对象
            4.把学生添加到集合
            5遍历集合（迭代器）
*/

/**
 * @author yulinhao
 * @version 1.0
 * @since 1.8
 */
public class CollectionDemo {
    /**
     *
      * @param args
     */
    public static void main(String[] args) {
        //创建Collection对象
        Collection<Student> c = new ArrayList<Student>();
        //创建学生对象
        Student s1 = new Student("林青霞", 30);
        Student s2 = new Student("林青", 40);
        Student s3 = new Student("林", 50);
        //把学生添加到集合
        c.add(s1);
        c.add(s2);
        c.add(s3);
        //遍历集合（迭代器
        Iterator<Student> it = c.iterator();
        while ((it.hasNext())) {
            Student s = it.next();
            System.out.println(s.getName() +","+s.getAge());

        }


    }
}
